﻿using AutoMapper;
using MediatR;
using UserLicense.Applicationes.Command;
using UserModels;
using UserRepositorys.Intface;

namespace UserLicense.Applicationes.CommandHandler
{
    public class RoleAddCommandHandler : IRequestHandler<RoleAddCommand, int>
    {
        private readonly IMapper _mapper;
        private readonly IRoleRepository _roleRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mapper"></param>
        public RoleAddCommandHandler(IMapper mapper, IRoleRepository roleRepository)
        {
            _mapper = mapper;
            _roleRepository = roleRepository;
        }
        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Handle(RoleAddCommand request, CancellationToken cancellationToken)
        {
            RoleInfoModel model=_mapper.Map<RoleAddCommand,RoleInfoModel>(request);
            return await _roleRepository.AddRole(model);
        }
    }
}
